home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 2
/
Amiga Tools 2.iso
/
tools
/
packer
/
xpkarchivepackage
/
xpkarchivelib
/
lib
/
genglue.rexx
next >
Wrap
OS/2 REXX Batch file
|
1995-03-09
|
3KB
|
181 lines
/*
©1993 by Matthias Meixner
USAGE: rx genglue.rexx <inputfile.fd
Format without Tags:
function(varlist)(reglist)
Format with Tags:
functionA(varlist)(reglist)
-> functionA , function
functionTagList(varlist)(reglist)
->functionTagList , functionTags
*/
basename=0
public=1
bias=0
line=readln(stdin)
line=compress(line)
do while line~==""
parse var line "##bias" newbias
parse var line "##base" newbase
parse var line func "(" varlist ")(" reglist ")"
if line="##end" then
exit(0)
else if line="##public" then
public=1
else if line="##private" then
public=0
else if newbias~=="" then
bias=newbias
else if newbase~=="" then
basename=newbase
else if left(func,1)~=="*" then do
if public=="1" then do
if right(func,1)=="A" then gentags(func,reglist,1,"")
if right(func,7)=="TagList" then gentags(func,reglist,4,"s")
gencode(func,reglist)
end
bias=bias+6
end
line=readln(stdin)
line=compress(line)
end
exit(0)
gencode: procedure expose basename bias
parse arg func,reglist
if Open("output",func".a",w)==0 then do
say "Cannot open output file"
exit(0)
end
saveregs=regs(reglist)
writeln("output",' SECTION "code",CODE')
writeln("output"," XDEF _"func)
writeln("output"," XREF "basename)
writeln("output","_"func":")
writeln("output"," movem.l "saveregs",-(sp)")
writeln("output"," move.l "basename",A6")
offset=4+((length(saveregs)+1)%3)*4
do while reglist~==""
parse var reglist reg","reglist
if length(reg)==2 then
writeln("output"," move.l "offset"(sp),"reg)
else
writeln("output"," movem.l "offset"(sp),"reg)
offset=offset+(length(reg)+1)%3*4
end
writeln("output"," jsr -"bias"(A6)")
writeln("output"," movem.l (sp)+,"saveregs)
writeln("output"," rts")
writeln("output"," END")
Close("output")
return 0
gentags: procedure expose basename bias
parse arg func,reglist,trunc,tag
saveregs=regs(reglist)
func=left(func,length(func)-trunc)tag
if Open("output",func".a",w)==0 then do
say "Cannot open output file"
exit(0)
end
writeln("output",' SECTION "code",CODE')
writeln("output"," XDEF _"func)
writeln("output"," XREF "basename)
writeln("output","_"func":")
writeln("output"," movem.l "saveregs",-(sp)")
writeln("output"," move.l "basename",A6")
offset=4+((length(saveregs)+1)%3)*4
do while reglist~==""
parse var reglist reg","reglist
if length(reglist)>0 then
if length(reg)==2 then
writeln("output"," move.l "offset"(sp),"reg)
else
writeln("output"," movem.l "offset"(sp),"reg)
else
writeln("output"," lea "offset"(sp),"reg)
offset=offset+(length(reg)+1)%3*4
end
writeln("output"," jsr -"bias"(A6)")
writeln("output"," movem.l (sp)+,"saveregs)
writeln("output"," rts")
writeln("output"," END")
Close("output")
return 0
regs: procedure
parse arg reglist
reglist=compress(reglist,",/")
reglist=upper(reglist)
saveregs="A6"
do while reglist~==""
reg=left(reglist,2)
reglist=right(reglist,length(reglist)-2)
if ~(reg="D0" | reg="D1" | reg="A0" | reg="A1") then
saveregs=saveregs||"/"||reg
end
return(saveregs)